{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "8cb80b2c-b924-4075-ae97-c97cce3cc641",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "1fa01448-7576-406f-8e97-c72bcc76d2bb",
   "metadata": {},
   "outputs": [],
   "source": [
    "plt.rcParams['font.sans-serif'] = \"SimHei\"\n",
    "plt.rcParams['axes.unicode_minus'] = False"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "06c0e653-00b4-42c2-92b7-00c87f0f8446",
   "metadata": {},
   "source": [
    "## 小麦种类预测"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e49d7e1b-229d-4856-a3c9-aa6339635cd1",
   "metadata": {},
   "source": [
    "### 1、数据获取"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "817c05c0-5fcc-4b3f-8eea-1d4bf04786b7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "      <th>4</th>\n",
       "      <th>5</th>\n",
       "      <th>6</th>\n",
       "      <th>7</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>15.26</td>\n",
       "      <td>14.84</td>\n",
       "      <td>0.8710</td>\n",
       "      <td>5.763</td>\n",
       "      <td>3.312</td>\n",
       "      <td>2.221</td>\n",
       "      <td>5.220</td>\n",
       "      <td>Kama</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>14.88</td>\n",
       "      <td>14.57</td>\n",
       "      <td>0.8811</td>\n",
       "      <td>5.554</td>\n",
       "      <td>3.333</td>\n",
       "      <td>1.018</td>\n",
       "      <td>4.956</td>\n",
       "      <td>Kama</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>14.29</td>\n",
       "      <td>14.09</td>\n",
       "      <td>0.9050</td>\n",
       "      <td>5.291</td>\n",
       "      <td>3.337</td>\n",
       "      <td>2.699</td>\n",
       "      <td>4.825</td>\n",
       "      <td>Kama</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>13.84</td>\n",
       "      <td>13.94</td>\n",
       "      <td>0.8955</td>\n",
       "      <td>5.324</td>\n",
       "      <td>3.379</td>\n",
       "      <td>2.259</td>\n",
       "      <td>4.805</td>\n",
       "      <td>Kama</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>16.14</td>\n",
       "      <td>14.99</td>\n",
       "      <td>0.9034</td>\n",
       "      <td>5.658</td>\n",
       "      <td>3.562</td>\n",
       "      <td>1.355</td>\n",
       "      <td>5.175</td>\n",
       "      <td>Kama</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>205</th>\n",
       "      <td>12.19</td>\n",
       "      <td>13.20</td>\n",
       "      <td>0.8783</td>\n",
       "      <td>5.137</td>\n",
       "      <td>2.981</td>\n",
       "      <td>3.631</td>\n",
       "      <td>4.870</td>\n",
       "      <td>Canadian</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>206</th>\n",
       "      <td>11.23</td>\n",
       "      <td>12.88</td>\n",
       "      <td>0.8511</td>\n",
       "      <td>5.140</td>\n",
       "      <td>2.795</td>\n",
       "      <td>4.325</td>\n",
       "      <td>5.003</td>\n",
       "      <td>Canadian</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>207</th>\n",
       "      <td>13.20</td>\n",
       "      <td>13.66</td>\n",
       "      <td>0.8883</td>\n",
       "      <td>5.236</td>\n",
       "      <td>3.232</td>\n",
       "      <td>8.315</td>\n",
       "      <td>5.056</td>\n",
       "      <td>Canadian</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>208</th>\n",
       "      <td>11.84</td>\n",
       "      <td>13.21</td>\n",
       "      <td>0.8521</td>\n",
       "      <td>5.175</td>\n",
       "      <td>2.836</td>\n",
       "      <td>3.598</td>\n",
       "      <td>5.044</td>\n",
       "      <td>Canadian</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>209</th>\n",
       "      <td>12.30</td>\n",
       "      <td>13.34</td>\n",
       "      <td>0.8684</td>\n",
       "      <td>5.243</td>\n",
       "      <td>2.974</td>\n",
       "      <td>5.637</td>\n",
       "      <td>5.063</td>\n",
       "      <td>Canadian</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>210 rows × 8 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "         0      1       2      3      4      5      6         7\n",
       "0    15.26  14.84  0.8710  5.763  3.312  2.221  5.220      Kama\n",
       "1    14.88  14.57  0.8811  5.554  3.333  1.018  4.956      Kama\n",
       "2    14.29  14.09  0.9050  5.291  3.337  2.699  4.825      Kama\n",
       "3    13.84  13.94  0.8955  5.324  3.379  2.259  4.805      Kama\n",
       "4    16.14  14.99  0.9034  5.658  3.562  1.355  5.175      Kama\n",
       "..     ...    ...     ...    ...    ...    ...    ...       ...\n",
       "205  12.19  13.20  0.8783  5.137  2.981  3.631  4.870  Canadian\n",
       "206  11.23  12.88  0.8511  5.140  2.795  4.325  5.003  Canadian\n",
       "207  13.20  13.66  0.8883  5.236  3.232  8.315  5.056  Canadian\n",
       "208  11.84  13.21  0.8521  5.175  2.836  3.598  5.044  Canadian\n",
       "209  12.30  13.34  0.8684  5.243  2.974  5.637  5.063  Canadian\n",
       "\n",
       "[210 rows x 8 columns]"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 读取seeds.tsv文件，最后一列是小麦品种，其他列是小麦特征\n",
    "data = pd.read_csv('../dataset/seeds.tsv', sep='\\t', header=None)\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "baa48ff9-1843-462e-86b9-c6f0c18b0df1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[15.26  , 14.84  ,  0.871 , ...,  3.312 ,  2.221 ,  5.22  ],\n",
       "       [14.88  , 14.57  ,  0.8811, ...,  3.333 ,  1.018 ,  4.956 ],\n",
       "       [14.29  , 14.09  ,  0.905 , ...,  3.337 ,  2.699 ,  4.825 ],\n",
       "       ...,\n",
       "       [13.2   , 13.66  ,  0.8883, ...,  3.232 ,  8.315 ,  5.056 ],\n",
       "       [11.84  , 13.21  ,  0.8521, ...,  2.836 ,  3.598 ,  5.044 ],\n",
       "       [12.3   , 13.34  ,  0.8684, ...,  2.974 ,  5.637 ,  5.063 ]])"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 转换成可控模型训练的模式，这个是不带标签的部分\n",
    "data.iloc[:, :-1].values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "02a81808-ad54-46af-bfa7-667c167fe3c7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['Kama', 'Kama', 'Kama', 'Kama', 'Kama', 'Kama', 'Kama', 'Kama',\n",
       "       'Kama', 'Kama', 'Kama', 'Kama', 'Kama', 'Kama', 'Kama', 'Kama',\n",
       "       'Kama', 'Kama', 'Kama', 'Kama', 'Kama', 'Kama', 'Kama', 'Kama',\n",
       "       'Kama', 'Kama', 'Kama', 'Kama', 'Kama', 'Kama', 'Kama', 'Kama',\n",
       "       'Kama', 'Kama', 'Kama', 'Kama', 'Kama', 'Kama', 'Kama', 'Kama',\n",
       "       'Kama', 'Kama', 'Kama', 'Kama', 'Kama', 'Kama', 'Kama', 'Kama',\n",
       "       'Kama', 'Kama', 'Kama', 'Kama', 'Kama', 'Kama', 'Kama', 'Kama',\n",
       "       'Kama', 'Kama', 'Kama', 'Kama', 'Kama', 'Kama', 'Kama', 'Kama',\n",
       "       'Kama', 'Kama', 'Kama', 'Kama', 'Kama', 'Kama', 'Rosa', 'Rosa',\n",
       "       'Rosa', 'Rosa', 'Rosa', 'Rosa', 'Rosa', 'Rosa', 'Rosa', 'Rosa',\n",
       "       'Rosa', 'Rosa', 'Rosa', 'Rosa', 'Rosa', 'Rosa', 'Rosa', 'Rosa',\n",
       "       'Rosa', 'Rosa', 'Rosa', 'Rosa', 'Rosa', 'Rosa', 'Rosa', 'Rosa',\n",
       "       'Rosa', 'Rosa', 'Rosa', 'Rosa', 'Rosa', 'Rosa', 'Rosa', 'Rosa',\n",
       "       'Rosa', 'Rosa', 'Rosa', 'Rosa', 'Rosa', 'Rosa', 'Rosa', 'Rosa',\n",
       "       'Rosa', 'Rosa', 'Rosa', 'Rosa', 'Rosa', 'Rosa', 'Rosa', 'Rosa',\n",
       "       'Rosa', 'Rosa', 'Rosa', 'Rosa', 'Rosa', 'Rosa', 'Rosa', 'Rosa',\n",
       "       'Rosa', 'Rosa', 'Rosa', 'Rosa', 'Rosa', 'Rosa', 'Rosa', 'Rosa',\n",
       "       'Rosa', 'Rosa', 'Rosa', 'Rosa', 'Canadian', 'Canadian', 'Canadian',\n",
       "       'Canadian', 'Canadian', 'Canadian', 'Canadian', 'Canadian',\n",
       "       'Canadian', 'Canadian', 'Canadian', 'Canadian', 'Canadian',\n",
       "       'Canadian', 'Canadian', 'Canadian', 'Canadian', 'Canadian',\n",
       "       'Canadian', 'Canadian', 'Canadian', 'Canadian', 'Canadian',\n",
       "       'Canadian', 'Canadian', 'Canadian', 'Canadian', 'Canadian',\n",
       "       'Canadian', 'Canadian', 'Canadian', 'Canadian', 'Canadian',\n",
       "       'Canadian', 'Canadian', 'Canadian', 'Canadian', 'Canadian',\n",
       "       'Canadian', 'Canadian', 'Canadian', 'Canadian', 'Canadian',\n",
       "       'Canadian', 'Canadian', 'Canadian', 'Canadian', 'Canadian',\n",
       "       'Canadian', 'Canadian', 'Canadian', 'Canadian', 'Canadian',\n",
       "       'Canadian', 'Canadian', 'Canadian', 'Canadian', 'Canadian',\n",
       "       'Canadian', 'Canadian', 'Canadian', 'Canadian', 'Canadian',\n",
       "       'Canadian', 'Canadian', 'Canadian', 'Canadian', 'Canadian',\n",
       "       'Canadian', 'Canadian'], dtype=object)"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 转换成可控模型训练的模式，这个是标签的部分\n",
    "data.iloc[:, -1].values"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "83e24af4-7939-4d63-91eb-099f3cb09364",
   "metadata": {},
   "source": [
    "### 2、分割数据集"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "06577e2f-12f9-4077-8501-777e8625a396",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 导入train_test_split函数，用于将数据集划分为训练集和测试集\n",
    "from sklearn.model_selection import train_test_split"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "02dd0ed4-8f50-401f-8313-e7e8108ce9dc",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 使用iloc方法选取data中的所有行和除了最后一列的所有列作为特征数据X，最后一列作为目标数据y\n",
    "# 然后将数据集划分为训练集（80%）和测试集（20%）\n",
    "X_train, X_test, y_train, y_test = train_test_split(data.iloc[:, :-1].values, data.iloc[:, -1].values)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fcbce424-7bf1-46a3-a87e-7d36cf4d2df1",
   "metadata": {},
   "source": [
    "### 3、模型训练"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "a72a92a5-f185-4b0b-97c2-582d789e6de2",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 导入KNeighborsClassifier类，用于构建K近邻分类器模型\n",
    "from sklearn.neighbors import KNeighborsClassifier"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "d3657ae9-1a6f-4a5f-975c-c3ccd580f0f5",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 创建K近邻分类器实例\n",
    "knn = KNeighborsClassifier()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "35d7a171-3fb3-4692-befe-2d53837e7e0f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style>#sk-container-id-2 {color: black;}#sk-container-id-2 pre{padding: 0;}#sk-container-id-2 div.sk-toggleable {background-color: white;}#sk-container-id-2 label.sk-toggleable__label {cursor: pointer;display: block;width: 100%;margin-bottom: 0;padding: 0.3em;box-sizing: border-box;text-align: center;}#sk-container-id-2 label.sk-toggleable__label-arrow:before {content: \"▸\";float: left;margin-right: 0.25em;color: #696969;}#sk-container-id-2 label.sk-toggleable__label-arrow:hover:before {color: black;}#sk-container-id-2 div.sk-estimator:hover label.sk-toggleable__label-arrow:before {color: black;}#sk-container-id-2 div.sk-toggleable__content {max-height: 0;max-width: 0;overflow: hidden;text-align: left;background-color: #f0f8ff;}#sk-container-id-2 div.sk-toggleable__content pre {margin: 0.2em;color: black;border-radius: 0.25em;background-color: #f0f8ff;}#sk-container-id-2 input.sk-toggleable__control:checked~div.sk-toggleable__content {max-height: 200px;max-width: 100%;overflow: auto;}#sk-container-id-2 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {content: \"▾\";}#sk-container-id-2 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-2 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-2 input.sk-hidden--visually {border: 0;clip: rect(1px 1px 1px 1px);clip: rect(1px, 1px, 1px, 1px);height: 1px;margin: -1px;overflow: hidden;padding: 0;position: absolute;width: 1px;}#sk-container-id-2 div.sk-estimator {font-family: monospace;background-color: #f0f8ff;border: 1px dotted black;border-radius: 0.25em;box-sizing: border-box;margin-bottom: 0.5em;}#sk-container-id-2 div.sk-estimator:hover {background-color: #d4ebff;}#sk-container-id-2 div.sk-parallel-item::after {content: \"\";width: 100%;border-bottom: 1px solid gray;flex-grow: 1;}#sk-container-id-2 div.sk-label:hover label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-2 div.sk-serial::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: 0;}#sk-container-id-2 div.sk-serial {display: flex;flex-direction: column;align-items: center;background-color: white;padding-right: 0.2em;padding-left: 0.2em;position: relative;}#sk-container-id-2 div.sk-item {position: relative;z-index: 1;}#sk-container-id-2 div.sk-parallel {display: flex;align-items: stretch;justify-content: center;background-color: white;position: relative;}#sk-container-id-2 div.sk-item::before, #sk-container-id-2 div.sk-parallel-item::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: -1;}#sk-container-id-2 div.sk-parallel-item {display: flex;flex-direction: column;z-index: 1;position: relative;background-color: white;}#sk-container-id-2 div.sk-parallel-item:first-child::after {align-self: flex-end;width: 50%;}#sk-container-id-2 div.sk-parallel-item:last-child::after {align-self: flex-start;width: 50%;}#sk-container-id-2 div.sk-parallel-item:only-child::after {width: 0;}#sk-container-id-2 div.sk-dashed-wrapped {border: 1px dashed gray;margin: 0 0.4em 0.5em 0.4em;box-sizing: border-box;padding-bottom: 0.4em;background-color: white;}#sk-container-id-2 div.sk-label label {font-family: monospace;font-weight: bold;display: inline-block;line-height: 1.2em;}#sk-container-id-2 div.sk-label-container {text-align: center;}#sk-container-id-2 div.sk-container {/* jupyter's `normalize.less` sets `[hidden] { display: none; }` but bootstrap.min.css set `[hidden] { display: none !important; }` so we also need the `!important` here to be able to override the default hidden behavior on the sphinx rendered scikit-learn.org. See: https://github.com/scikit-learn/scikit-learn/issues/21755 */display: inline-block !important;position: relative;}#sk-container-id-2 div.sk-text-repr-fallback {display: none;}</style><div id=\"sk-container-id-2\" class=\"sk-top-container\"><div class=\"sk-text-repr-fallback\"><pre>KNeighborsClassifier()</pre><b>In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. <br />On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.</b></div><div class=\"sk-container\" hidden><div class=\"sk-item\"><div class=\"sk-estimator sk-toggleable\"><input class=\"sk-toggleable__control sk-hidden--visually\" id=\"sk-estimator-id-2\" type=\"checkbox\" checked><label for=\"sk-estimator-id-2\" class=\"sk-toggleable__label sk-toggleable__label-arrow\">KNeighborsClassifier</label><div class=\"sk-toggleable__content\"><pre>KNeighborsClassifier()</pre></div></div></div></div></div>"
      ],
      "text/plain": [
       "KNeighborsClassifier()"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 使用训练集数据对K近邻分类器进行训练\n",
    "knn.fit(X_train, y_train)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f22d8ae3-2109-4d74-aabf-f13faf5c92a3",
   "metadata": {},
   "source": [
    "### 4、模型预测"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "139ecc67-b5c7-4281-b11e-c0b8dece2ca9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['Rosa', 'Canadian', 'Canadian', 'Rosa', 'Canadian', 'Kama', 'Rosa',\n",
       "       'Kama', 'Canadian', 'Canadian', 'Kama', 'Canadian', 'Canadian',\n",
       "       'Rosa', 'Rosa', 'Kama', 'Canadian', 'Rosa', 'Kama', 'Rosa', 'Rosa',\n",
       "       'Rosa', 'Canadian', 'Kama', 'Rosa', 'Canadian', 'Kama', 'Kama',\n",
       "       'Rosa', 'Kama', 'Kama', 'Kama', 'Rosa', 'Kama', 'Canadian', 'Rosa',\n",
       "       'Canadian', 'Rosa', 'Kama', 'Canadian', 'Canadian', 'Rosa', 'Kama',\n",
       "       'Rosa', 'Canadian', 'Canadian', 'Rosa', 'Kama', 'Kama', 'Canadian',\n",
       "       'Canadian', 'Rosa', 'Canadian'], dtype=object)"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 使用训练好的K近邻分类器对测试集数据进行预测\n",
    "y_pred = knn.predict(X_test)\n",
    "y_pred"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3005d1f6-52a4-4bfd-801f-d25792fa7e71",
   "metadata": {},
   "source": [
    "### 5、模型评估"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "820405d0-89a5-4fe2-b4e8-5efd48c14937",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.9056603773584906"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 计算K近邻分类器在测试集上的准确率\n",
    "knn.score(X_test, y_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "f364f8cf-0d1e-486a-86dc-c67500ab487f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['Rosa', 'Canadian', 'Canadian', 'Rosa', 'Canadian', 'Kama', 'Rosa',\n",
       "       'Kama', 'Canadian', 'Canadian', 'Kama', 'Canadian', 'Canadian',\n",
       "       'Rosa', 'Rosa', 'Rosa', 'Canadian', 'Rosa', 'Kama', 'Rosa', 'Rosa',\n",
       "       'Rosa', 'Canadian', 'Kama', 'Rosa', 'Kama', 'Kama', 'Kama', 'Rosa',\n",
       "       'Kama', 'Kama', 'Kama', 'Rosa', 'Kama', 'Canadian', 'Rosa',\n",
       "       'Canadian', 'Kama', 'Kama', 'Canadian', 'Canadian', 'Rosa', 'Kama',\n",
       "       'Rosa', 'Canadian', 'Canadian', 'Rosa', 'Kama', 'Kama', 'Canadian',\n",
       "       'Kama', 'Rosa', 'Kama'], dtype=object)"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "array(['Rosa', 'Canadian', 'Canadian', 'Rosa', 'Canadian', 'Kama', 'Rosa',\n",
       "       'Kama', 'Canadian', 'Canadian', 'Kama', 'Canadian', 'Canadian',\n",
       "       'Rosa', 'Rosa', 'Kama', 'Canadian', 'Rosa', 'Kama', 'Rosa', 'Rosa',\n",
       "       'Rosa', 'Canadian', 'Kama', 'Rosa', 'Canadian', 'Kama', 'Kama',\n",
       "       'Rosa', 'Kama', 'Kama', 'Kama', 'Rosa', 'Kama', 'Canadian', 'Rosa',\n",
       "       'Canadian', 'Rosa', 'Kama', 'Canadian', 'Canadian', 'Rosa', 'Kama',\n",
       "       'Rosa', 'Canadian', 'Canadian', 'Rosa', 'Kama', 'Kama', 'Canadian',\n",
       "       'Canadian', 'Rosa', 'Canadian'], dtype=object)"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "array([ True,  True,  True,  True,  True,  True,  True,  True,  True,\n",
       "        True,  True,  True,  True,  True,  True, False,  True,  True,\n",
       "        True,  True,  True,  True,  True,  True,  True, False,  True,\n",
       "        True,  True,  True,  True,  True,  True,  True,  True,  True,\n",
       "        True, False,  True,  True,  True,  True,  True,  True,  True,\n",
       "        True,  True,  True,  True,  True, False,  True, False])"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 输出预测结果和原始标签，对比观察预测效果\n",
    "display(y_test, y_pred)\n",
    "y_test == y_pred"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "12ee7ba4-56ef-4289-a1f9-f8d57a2b2043",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
